
/*
 * Copyright (C) 2010 Bitglue. All rights reserved.
 *
 * $Id: DeploymentController.java bself $
 */

package com.bitglue.web.admin.webmvc;

import com.bitglue.web.admin.util.TransformUtils;
import com.bitglue.web.admin.util.XmlTreeUtils;
import com.bitglue.web.admin.webmvc.model.DeploymentModel;

import java.lang.reflect.Method;
import java.net.URL;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.jar.JarInputStream;
import java.util.zip.ZipEntry;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import org.w3c.dom.Element;

/**
 * DeploymentController for deploying new bundles.
 * @author Bryan Patrick Self
 */
@Controller("deploymentController")
@SessionAttributes(types = DeploymentModel.class)
public class DeploymentController {

    protected final Logger log = Logger.getLogger(getClass());

    @Autowired
    @Qualifier("bundleContext")
    private BundleContext bundleContext;

    @RequestMapping(value = "/deploymemt.do", method = RequestMethod.GET)
    public ModelAndView bundleSetup(HttpServletRequest req) {
        log.debug("creating new deployment model for client "
          + req.getRemoteAddr());
        DeploymentModel deployModel = new DeploymentModel();
        return new ModelAndView("deployment", "deployModel", deployModel);
    }

    @RequestMapping(value = "/doDeployment.do")
    public void getDeployment(@RequestParam("ID") long bundleId,
      HttpServletRequest req, HttpServletResponse resp) throws Exception {
        resp.setContentType("text/xml");
        log.debug("retrieving classpath entries for client "
          + req.getRemoteAddr());

    }

}
